#!/bin/ash

LOGFILE=/var/log/messages

case $1 in
	'barriers')
		awk '
			BEGIN {
				open_count==0;
				close_count==0;
				printf("\n  Barrier activations report\n\n");
				printf("%-20s %-10s %-15s\n", "IP Address", "State", "Timestamp");
				printf("%-20s %-10s %-15s\n", "--------------------", "----------", "---------------");
			}
			/daemon\.info.*OPEN/ {
				printf("%-20s %-10s %s %s %s\n", $8, "OPEN", $1, $2, $3);
				open_count++;
			}
			/daemon\.info.*CLOSED/ {
				printf("%-20s %-10s %s %s %s\n", $8, "CLOSE", $1, $2, $3);
				close_count++;
			}
			END {
				printf("\nTotal number of open events is %i\n", open_count);
				printf("Total number of close events is %i\n", close_count);
			}' $LOGFILE | more
	;;

	'controllers')
		awk '
			BEGIN {
				count==0;
				printf("\n  Controller activations report\n\n");
				printf("%-20s %-15s\n", "IP Address", "Timestamp");
				printf("%-20s %-15s\n", "--------------------", "---------------");
			}
			/daemon\.info.*New client/ {
				printf("%-20s %s %s %s\n", $10, $1, $2, $3);
				count++;
			}
			END {
				printf("\nTotal number of controller activations is %i\n", count);
			}' $LOGFILE | more
	;;
	*)
		echo $" Usage: report { barriers | controllers }"
	;;
esac

